package com.xggstudio.crm.ui.mvp.v;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.xggstudio.crm.R;
import com.xggstudio.crm.base.BaseActivity;
import com.xggstudio.crm.ui.mvp.v.adapter.CommonAdapter;
import com.xggstudio.crm.ui.mvp.v.adapter.ViewHolder;
import java.util.ArrayList;
import java.util.List;

public class OtherListActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener {

    private Toolbar toolbar;

    private SwipeRefreshLayout refresh;

    private RecyclerView list;

    private TextView bar_text;

    private CommonAdapter adapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_other_list;
    }

    @Override
    protected void init(Bundle savedInstanceState) {

        initView();
    }

    @SuppressLint("RestrictedApi")
    private void initView(){

        bar_text = (TextView) $(R.id.bar_text);
        toolbar = (Toolbar) $(R.id.toolbar);
        refresh = (SwipeRefreshLayout) $(R.id.refresh);
        list = (RecyclerView) $(R.id.list);

        bar_text.setText(getResources().getString(R.string.manger_other));
        toolbar.setTitle("");
        setSupportActionBar(toolbar);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);

        refresh.setOnRefreshListener(this);

        initadattper();
    }

    private void initadattper(){
        List<String> data = new ArrayList<>();

        for (int i = 0; i < 6; i++) {
            data.add("");
        }

        adapter = new CommonAdapter<String>(this,R.layout.view_mager_other,data) {

            @Override
            public void convert(ViewHolder holder, String s, int position) {

            }
        };

        list.setLayoutManager(new LinearLayoutManager(this));
        list.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main_bar_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
            case R.id.menu_add:
                startToActivity(AddOrEditOtherActivity.class);
                break;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onRefresh() {
        refresh.setRefreshing(false);
    }
}
